package com.ycode.bang.anbang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.google.gson.Gson;
import com.ycode.bang.anbang.MyApp;
import com.ycode.bang.anbang.R;
import com.ycode.bang.anbang.adapter.ImageAdapter;
import com.ycode.bang.anbang.adapter.RecordAdapter;
import com.ycode.bang.anbang.baseui.BaseActivity;
import com.ycode.bang.anbang.customview.MyGridView;
import com.ycode.bang.anbang.model.OrderDetil;
import com.ycode.bang.anbang.model.recordModel;
import com.ycode.bang.anbang.network.FinalHttpUtil;
import com.ycode.bang.anbang.refresh.SwipeRefreshLayout;
import com.ycode.bang.anbang.utils.RequestMapDev;
import com.ycode.bang.anbang.utils.ToastUtil;

import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 这个是公共报修的后三个工单详情、、maosongsong和其他的投诉建议什么的公用
 */
public class RepairingDetailActivity extends BaseActivity implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener, SwipeRefreshLayout.OnLoadListener {
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.tv_diftitle)
    TextView mTvDiftitle;//不同内容的标题
    @InjectView(R.id.tvt_address)
    TextView mTvAddress;
    @InjectView(R.id.tvt_name)
    TextView mTvtName;
    @InjectView(R.id.tvt_number)
    TextView mTvNumber;
    @InjectView(R.id.tvt_leixing)
    TextView mTvLeixing;
    @InjectView(R.id.tvt_neirong)
    TextView mTvNeirong;
    @InjectView(R.id.tvt_jibie)
    TextView mTvJibie;
    @InjectView(R.id.tvt_shijian)
    TextView mTvShijian;
    @InjectView(R.id.tvt_laiyuan)
    TextView mTvLaiyuan;

    @InjectView(R.id.tv_bumen)
    TextView mTvBumen;
    @InjectView(R.id.tv_renyuan)
    TextView mTvRenyuan;
    @InjectView(R.id.tv_fengpeishijian)
    TextView mTvFengpeishijian;
    @InjectView(R.id.tv_bumen2)
    TextView mTvBumen2;
    @InjectView(R.id.tv_renyuan2)
    TextView mTvRenyuan2;
    //    @InjectView(R.id.tv_jinxingshijian)
//    TextView mTvJinxingshijian;
//    @InjectView(R.id.tv_jilu)
//    TextView mTvJilu;
//    @InjectView(R.id.tv_jilushijian)
//    TextView mTvJilushijian;
    //服务评价
    @InjectView(R.id.pingfeng)
    RatingBar mRating;
    @InjectView(R.id.tv_pingjianierong)
    TextView mTvPingjianierong;
    @InjectView(R.id.tv_pingjiashijian)
    TextView mTvPingjiashijian;
    @InjectView(R.id.lin_fuwu)
    LinearLayout linFuwu;
    @InjectView(R.id.lin_jibie)
    LinearLayout lin_jibie;//报修级别

    //回访记录
    @InjectView(R.id.huifang_pj)
    TextView mHuifangPj;
    @InjectView(R.id.tv_huifang_name)
    TextView MtvHuifangname;//这个是回访人和名字都有的
    @InjectView(R.id.tv_huifangshijian)
    TextView mTvHuifangshijian;
    @InjectView(R.id.lin_huifang)
    LinearLayout linHuifang;

    //关闭原因
    @InjectView(R.id.tv_closeresone)
    TextView mTvClosereason;
    @InjectView(R.id.lin_closereason)
    LinearLayout linClosereson;
    @InjectView(R.id.lin_top)
    LinearLayout linTop;

    @InjectView(R.id.gridview)
    MyGridView mGridView;
    //    @InjectView(R.id.gridview2)
//    MyGridView mGridView2;
    @InjectView(R.id.btn_done)
    Button mBtnDone;//确认完成
    @InjectView(R.id.btn_again)
    Button mBtnAgain;//再次处理
    @InjectView(R.id.btn_revisit)
    Button mBtnRevisit;//回访
    @InjectView(R.id.btn_close)
    Button mBtnClose;//关闭订单/管理人员的按钮/处理人员显示/

    @InjectView(R.id.layliucheng)
    LinearLayout liucheng;//流程

    @InjectView(R.id.chulijilu)
    LinearLayout chulijilu;//处理记录


    @InjectView(R.id.weixiujilu)
    LinearLayout weixiujilu;//维修记录

    @InjectView(R.id.fengpeixx)
    LinearLayout fengpeixx;//分配信息

    @InjectView(R.id.lin_doing)
    LinearLayout linDoing;//进行中下面的按钮
    @InjectView(R.id.lin_revisit)
    LinearLayout liRevisit;//已完成下面的按钮
    @InjectView(R.id.lin_close)
    LinearLayout liClose;//个人报修中进行中下面的按钮/关闭按钮
    @InjectView(R.id.lin_waitpay)
    LinearLayout liWaitpay;//个人报修中进行中下面的按钮、等待付款
    @InjectView(R.id.lin_closed)
    LinearLayout liClosed;//个人报修中已经关闭的订单的显示按钮，无点击、、、、、还要已经申请关闭的按钮

    @InjectView(R.id.btn_waitpay)
    Button mBtnWaitpay;//待支付无点击时间，仅显示待支付价格

    RecordAdapter mEeadapter;

    @InjectView(R.id.lin_shouli_public)
    LinearLayout linShouliPublic;//受理人员下面的功能按钮
    @InjectView(R.id.add)
    Button mBtnadd;//添加记录
    @InjectView(R.id.btn_done2)
    Button mBtnDone2;//受理人员的确认完成
    @InjectView(R.id.close)
    Button close;//受理人员的申请关闭
    @InjectView(R.id.tvt_fshwijian)
    TextView mTvFushijiang;


    @InjectView(R.id.Lin_money)
    LinearLayout Lin_money;//已经支付
    @InjectView(R.id.money)
    TextView money;
    public ImageAdapter mAdapter = null;
    public ImageAdapter mAdapter2 = null;
    List<String> mList = new ArrayList<>();
    List<String> mList2 = new ArrayList<>();

    int state = 0;//判断是哪个状态，1是新接收；2是进行中；3是已处理；4是已完成
    int tag = 0;//1是公共报修，2是个人报修，3是投诉，4是建议
    public int id;
    private OrderDetil orderDetil = new OrderDetil();
    private String INTERFACE_PATH = "";//接口路径
    private String INTERFACE_PATH_Finish = "";//接口路径，确认完成
    @InjectView(R.id.swipe_container)
    public SwipeRefreshLayout mSwipeLayout;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            //要做的事情，这里再次调用此Runnable对象，以实现每1秒实现一次的定时器操作
//            handler.postDelayed(this, 1500);

            if (mSwipeLayout != null) {
                mSwipeLayout.setRefreshing(false);
            }
            if (mSwipeLayout != null) {
                mSwipeLayout.setLoading(false);
            }
            // mListAdapter.notifyDataSetChanged();

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_repairing_detail);
        ButterKnife.inject(this);
        if (this.getIntent().getExtras() != null) {
            Bundle bundle = this.getIntent().getExtras();
            state = bundle.getInt("state");
            tag = bundle.getInt("tag");
            id = bundle.getInt("id");
        }
        showBtn();
        initView();
        showDifferentdata();
        initData();
    }

    public void initView() {
        initSwipe();
        if (MyApp.instance.isManage()) {
            linShouliPublic.setVisibility(View.GONE);
        } else {
            mBtnRevisit.setVisibility(View.GONE);
            linShouliPublic.setVisibility(View.VISIBLE);
        }

        switch (tag) {
            case 1:
                title.setText("报修详情");
                break;
            case 2:
                title.setText("报修详情");
                break;
            case 3:
                title.setText("投诉详情");
                break;
            case 4:
                title.setText("建议详情");
                break;
            default:
                title.setText("未知");
                break;
        }
//        title.setText("报修详情");
//        if (tag == 3)
//            title.setText("投诉详情");
//        title.setText("报修详情");
//        if (tag == 3)
//            title.setText("建议详情");

        //这三行代码是把页面定位到最上面
        linTop.setFocusable(true);
        linTop.setFocusableInTouchMode(true);
        linTop.requestFocus();

        mBtnDone.setOnClickListener(this);
        mBtnAgain.setOnClickListener(this);
        mBtnRevisit.setOnClickListener(this);
        mBtnClose.setOnClickListener(this);
        mBtnadd.setOnClickListener(this);
        mBtnDone2.setOnClickListener(this);
        close.setOnClickListener(this);
    }

    /**
     * 初始化Swipe
     */
    private void initSwipe() {
        mSwipeLayout.setOnRefreshListener(this);
        mSwipeLayout.setOnLoadListener(this);
        mSwipeLayout.setColor(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        mSwipeLayout.setMode(SwipeRefreshLayout.Mode.BOTH);
        mSwipeLayout.setLoadNoFull(true);//是否需要上拉加载
    }

    /**
     * 根据从不同的地方进来（投诉或者建议那块），先不同的内容信息
     */
    public void showDifferentdata() {
        if (tag == 3) {
            mTvDiftitle.setText("投诉信息");
            mTvNeirong.setText("投诉内容");
            mTvShijian.setText("投诉时间");
            mTvLeixing.setVisibility(View.GONE);
            mTvJibie.setVisibility(View.GONE);
        } else if (tag == 4) {
            mTvDiftitle.setText("建议信息");
            mTvNeirong.setText("建议内容");
            mTvShijian.setText("建议时间");
            mTvLeixing.setVisibility(View.GONE);
            mTvJibie.setVisibility(View.GONE);
            liRevisit.setVisibility(View.GONE);
            linClosereson.setVisibility(View.GONE);
        }

    }

    public void initData() {
        if (tag == 1) {
            INTERFACE_PATH = RequestMapDev.GetOrderDetil;
            INTERFACE_PATH_Finish = RequestMapDev.ConfirmCompleteOrder;
        } else if (tag == 2) {
            INTERFACE_PATH = RequestMapDev.GetOrderDetil2;
        } else if (tag == 3) {
            INTERFACE_PATH = RequestMapDev.GetOrderDetil3;
            INTERFACE_PATH_Finish = RequestMapDev.ConfirmCompleteOrder3;
        } else if (tag == 4) {//确认完成
            INTERFACE_PATH = RequestMapDev.GetOrderDetil4;
        }
        getOrderDetil();
//        }
//        mAdapter = new ImageAdapter(this, mList);
//
//        mGridView.setAdapter(mAdapter);

    }

    /**
     * 根据状态显示按钮
     */
    public void showBtn() {//还要判断用户的属性，为管理还是受理人员
        if (state == 2 && tag == 1) {
            linShouliPublic.setVisibility(View.VISIBLE);
        } else if (state == 2 && tag == 2) {
            close.setVisibility(View.VISIBLE);
            mBtnDone2.setText("发起账单");
            linShouliPublic.setVisibility(View.VISIBLE);
        } else if (state == 2 && tag == 3) {
            close.setText("转报修");
            close.setVisibility(View.VISIBLE);
            linShouliPublic.setVisibility(View.VISIBLE);
        } else if (state == 3) {
            linDoing.setVisibility(View.VISIBLE);
            linShouliPublic.setVisibility(View.GONE);
        } else if (state == 4) {
            linShouliPublic.setVisibility(View.GONE);
            liRevisit.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_done:
                doneOrder();
                break;
            case R.id.btn_again:
                Intent intent2 = new Intent(this, DealAgain.class);
                bundle.putInt("orderId", orderDetil.getId());
                bundle.putInt("tag", tag);
                intent2.putExtras(bundle);
                startActivity(intent2);
                finish();
                break;
            case R.id.btn_revisit:
                Intent intent3 = new Intent(this, CallBackActivity.class);
                Bundle bundle2 = new Bundle();
                bundle2.putInt("tag", tag);
                bundle2.putInt("orderId", orderDetil.getId());
                intent3.putExtras(bundle2);
                startActivity(intent3);
                finish();
                break;
            case R.id.close:
                if (close.getText().toString().equals("转报修")) {
                    Intent intent4 = new Intent(this, ChangeToOrderActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("orderId", orderDetil.getId());
                    bundle.putString("name", orderDetil.getApplicationName());
                    bundle.putString("phone", orderDetil.getPhoneNumber());
                    bundle.putString("address", orderDetil.getAddress());
                    intent4.putExtras(bundle);
                    startActivity(intent4);
                    finish();
                } else {
                    Intent intent4 = new Intent(this, CloseActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("orderId", orderDetil.getId());
                    intent4.putExtras(bundle);
                    startActivity(intent4);
                    finish();
                }
                break;
            case R.id.btn_done2:
                if (mBtnDone2.getText().toString().equals("发起账单")) {
                    Intent intent5 = new Intent(this, BillActivity.class);
                    bundle.putInt("orderId", orderDetil.getId());
                    bundle.putInt("assignmentRecordId", orderDetil.getAssignmentRecordId());
                    intent5.putExtras(bundle);
                    startActivity(intent5);
                    finish();
                } else {
                    Intent intent5 = new Intent(this, DoneOrderActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("tag", tag);
                    bundle.putInt("orderId", orderDetil.getId());
                    intent5.putExtras(bundle);
                    startActivity(intent5);
                    finish();
                }
                break;
            case R.id.add:
                Intent intent6 = new Intent(this, AddRecordActivity.class);
                bundle.putInt("tag", tag);
                bundle.putInt("orderId", orderDetil.getId());
                if (tag == 1) {
                    bundle.putInt("assignmentRecordId", orderDetil.getAssignmentList().get(orderDetil.getAssignmentList().size() - 1).getId());
                } else {
                    bundle.putInt("assignmentRecordId", orderDetil.getAssignmentRecordId());
                }
                intent6.putExtras(bundle);
                startActivity(intent6);
                finish();
                break;
            case R.id.btn_close:
                if (mBtnClose.getText().equals("关闭订单"))
                    closeOrder();
                break;
        }
    }

    @Override
    protected void getSuccessRequest(Object response, int flag) {

    }

    /**
     * 关闭工单、管理人员功能
     */
    private void closeOrder() {
        AjaxParams mAjaxParam = new AjaxParams();
        mAjaxParam.put("csrfToken", MyApp.instance.getToken());
        mAjaxParam.put("orderId", id + "");
        FinalHttpUtil.get(RequestMapDev.CloseOrder, mAjaxParam, new AjaxCallBack<String>() {
            @Override
            public void onSuccess(String o) {
                super.onSuccess(o);
                //放置数据
                try {
                    JSONObject jsonObject = new JSONObject(o.toString());
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("message");
                    String data = jsonObject.getString("data");
                    if (status.equals("0")) {
                        Log.e("这个接口是成功的", o);
                        Gson gson = new Gson();
                        ToastUtil.show(RepairingDetailActivity.this, "关闭成功！");
                        finish();
                    } else {
                        ToastUtil.show(RepairingDetailActivity.this, msg.toString());
                    }
                } catch (Exception e) {
                    ToastUtil.show(RepairingDetailActivity.this, e.toString());
                }
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                loginout_550(errorNo);
//                ToastUtil.show(RepairingDetailActivity.this, strMsg);
            }
        });
    }

    /**
     * 管理人员确认完成工单
     */
    private void doneOrder() {
        AjaxParams mAjaxParam = new AjaxParams();
        mAjaxParam.put("csrfToken", MyApp.instance.getToken());
        mAjaxParam.put("orderId", id + "");
        FinalHttpUtil.post(INTERFACE_PATH_Finish, mAjaxParam, new AjaxCallBack<String>() {
            @Override
            public void onSuccess(String o) {
                super.onSuccess(o);
                //放置数据
                try {
                    JSONObject jsonObject = new JSONObject(o.toString());
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("message");
                    String data = jsonObject.getString("data");
                    if (status.equals("0")) {
                        Log.e("这个接口是成功的", o);
                        Gson gson = new Gson();
                        ToastUtil.show(RepairingDetailActivity.this, "确认成功！");
                        finish();
                    } else {
                        ToastUtil.show(RepairingDetailActivity.this, msg.toString());
                    }
                } catch (Exception e) {
                    ToastUtil.show(RepairingDetailActivity.this, e.toString());
                }
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                loginout_550(errorNo);
//                ToastUtil.show(RepairingDetailActivity.this, strMsg);
            }
        });
    }

    /**
     * 获取受理工单详情
     */
    private void getOrderDetil() {
        AjaxParams mAjaxParam = new AjaxParams();
        mAjaxParam.put("csrfToken", MyApp.instance.getToken());
        mAjaxParam.put("orderId", id + "");
        if (MyApp.instance.isManage()) {
            mAjaxParam.put("type", "1");
        } else {
            mAjaxParam.put("type", "0");
        }
        FinalHttpUtil.get(INTERFACE_PATH, mAjaxParam, new AjaxCallBack<String>() {
            @Override
            public void onSuccess(String o) {
                super.onSuccess(o);
                //放置数据
                try {
                    JSONObject jsonObject = new JSONObject(o.toString());
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("message");
                    String data = jsonObject.getString("data");
                    if (status.equals("0")) {
                        Log.e("这个接口是成功的", o);
                        Gson gson = new Gson();
                        orderDetil = gson.fromJson(data, OrderDetil.class);
                        if (tag == 1) {
                            setData(orderDetil);
                        } else if (tag == 2) {
                            setData2(orderDetil);
                        } else if (tag == 3) {
                            setData(orderDetil);
                        } else if (tag == 4) {
                            setData4(orderDetil);
                        }

                    } else {
                        ToastUtil.show(RepairingDetailActivity.this, msg.toString());
                    }
                } catch (Exception e) {
//                    ToastUtil.show(RepairingDetailActivity.this, e.toString());
                }
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                loginout_550(errorNo);
//                ToastUtil.show(RepairingDetailActivity.this, strMsg);
            }
        });
    }

    public void setData(OrderDetil orderDetil) {//公共和投诉一样，所以用一个
        mTvAddress.setText(orderDetil.getAddress());
        mTvtName.setText(orderDetil.getApplicationName());
        mTvNumber.setText(orderDetil.getPhoneNumber());
        if (!TextUtils.isEmpty(orderDetil.getType())) {
            mTvLeixing.setText("报修类型:" + orderDetil.getType());
            mTvLeixing.setVisibility(View.VISIBLE);
        } else {
            mTvLeixing.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(orderDetil.getProject())) {
            mTvLeixing.setText("报修项目:" + orderDetil.getProject());
            mTvLeixing.setVisibility(View.VISIBLE);
        } else {
//            mTvLeixing.setVisibility(View.GONE);
        }
        if (tag == 1 || tag == 2) {
            mTvNeirong.setText("报修内容:" + orderDetil.getContent());
            mTvShijian.setText("报修时间:" + orderDetil.getCreateTime());
        } else if (tag == 3) {
            mTvNeirong.setText("投诉内容:" + orderDetil.getContent());
            mTvShijian.setText("投诉时间:" + orderDetil.getCreateTime());
        } else if (tag == 4) {
            mTvNeirong.setText("建议内容:" + orderDetil.getContent());
            mTvShijian.setText("建议时间:" + orderDetil.getCreateTime());
        }
        mTvLaiyuan.setText("工单来源:" + orderDetil.getSource());
        if (!TextUtils.isEmpty(orderDetil.getLevel())) {
            mTvJibie.setText("报修级别:" + orderDetil.getLevel());
        } else {
            lin_jibie.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(orderDetil.getCommentContent())) {
            linFuwu.setVisibility(View.VISIBLE);
            mTvPingjianierong.setText(orderDetil.getCommentContent());
            mTvPingjiashijian.setText(orderDetil.getCommentTime());
            mRating.setRating(orderDetil.getStar());
        }
        if (orderDetil.getComment() != null) {
            linFuwu.setVisibility(View.VISIBLE);
            mTvPingjianierong.setText(orderDetil.getComment().getCommentContent());
            mTvPingjiashijian.setText(orderDetil.getComment().getCommentTime());
            mRating.setRating(orderDetil.getComment().getStar());
        }
        if (orderDetil.getVisit() != null) {
            linHuifang.setVisibility(View.VISIBLE);
            mHuifangPj.setText(orderDetil.getVisit().getVisitContent());
            MtvHuifangname.setText(orderDetil.getVisit().getVisitName() + "   " + orderDetil.getVisit().getVisitPhone());
            mTvHuifangshijian.setText(orderDetil.getVisit().getVisitTime());
            liRevisit.setVisibility(View.GONE);
        }
        if (orderDetil.getPictureUrl() != null) {
            mList.addAll(orderDetil.getPictureUrl());
            mAdapter = new ImageAdapter(this, mList);
            mGridView.setAdapter(mAdapter);
        }
        if (!TextUtils.isEmpty(orderDetil.getCloseReason())) {
            if (MyApp.instance.isManage() && state == 2) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.VISIBLE);
                linShouliPublic.setVisibility(View.GONE);
            } else if (state == 2) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.VISIBLE);
                mBtnClose.setBackgroundResource(R.color.gray);
                mBtnClose.setText("已申请关闭");
                linShouliPublic.setVisibility(View.GONE);
            } else if (state == 4) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.GONE);
                linShouliPublic.setVisibility(View.GONE);
            }
        }
        if (orderDetil.getRepairBill() != null) {
            if (!MyApp.instance.isManage()) {
                linShouliPublic.setVisibility(View.GONE);
                mBtnClose.setText("待支付：" + orderDetil.getRepairBill().getMoney() + "元");
                mBtnClose.setBackgroundResource(R.color.gray);
                liClose.setVisibility(View.VISIBLE);
            } else {
                mBtnClose.setText("待支付：" + orderDetil.getRepairBill().getMoney() + "元");
                mBtnClose.setBackgroundResource(R.color.gray);
                liClose.setVisibility(View.VISIBLE);
            }
        }
        if (!MyApp.instance.isManage() && tag == 2 && state == 4) {
            linShouliPublic.setVisibility(View.GONE);
        }
        if (orderDetil.getRepairBill() != null) {
            if (orderDetil.getRepairBill().getBillingStatus().equals("已支付")) {
                Lin_money.setVisibility(View.VISIBLE);
                money.setText(orderDetil.getRepairBill().getMoney() + "元");
            }
        }
        close.setVisibility(View.GONE);//去掉申请关闭按钮
        mTvFushijiang.setVisibility(View.GONE);//公共没有服务时间

        if (MyApp.instance.isManage() && orderDetil.getAssignmentList() != null) {

            if (orderDetil.getAssignmentList() != null) {
                for (int j = 0; j < orderDetil.getAssignmentList().size(); j++) {
                    if (orderDetil.getAssignmentList().get(j).getRecordList().size() > 0) {//有维修记录再显示维修信息
                        View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
                        TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
                        TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
                        TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
                        TextView mTvWanchengshijian = (TextView) view.findViewById(R.id.tv_wanchengshijian);
                        TextView title = (TextView) view.findViewById(R.id.title);
                        TextView tv_jieshushijian = (TextView) view.findViewById(R.id.tv_jieshushijian);
                        LinearLayout linTitle = (LinearLayout) view.findViewById(R.id.lin_title);
                        LinearLayout weixiujilu2 = (LinearLayout) view.findViewById(R.id.weixiujilu);
//                        if (j == 0) {
//                            linTitle.setVisibility(View.VISIBLE);
//                        } else {
//                            linTitle.setVisibility(View.GONE);
//                        }
                        linTitle.setVisibility(View.GONE);
                        title.setText("维修记录");
                        buMeng.setText("部门：" + orderDetil.getAssignmentList().get(j).getDepartmentName());
                        renYuan.setText("人员：" + orderDetil.getAssignmentList().get(j).getName());
                        mTvJilushijian.setText("进行时间：" + orderDetil.getAssignmentList().get(j).getAssignedTime());
                        if (!TextUtils.isEmpty(orderDetil.getAssignmentList().get(j).getCompleteTime())) {
                            mTvWanchengshijian.setText("完成时间：" + orderDetil.getAssignmentList().get(j).getCompleteTime());
                        } else {
                            mTvWanchengshijian.setVisibility(View.GONE);
                        }
                        if (!TextUtils.isEmpty(orderDetil.getAssignmentList().get(j).getFinishTime())) {
                            tv_jieshushijian.setVisibility(View.VISIBLE);
                            tv_jieshushijian.setText("结束时间：" + orderDetil.getAssignmentList().get(j).getFinishTime());
                        }
                        weixiujilu.addView(view);
                        weixiujilu.getChildAt(0).findViewById(R.id.lin_title).setVisibility(View.VISIBLE);
                        if (orderDetil.getAssignmentList().get(j).getRecordList().size() > 0) {
                            for (int i = 0; i < orderDetil.getAssignmentList().get(j).getRecordList().size(); i++) {
                                List<String> mList = new ArrayList<>();
                                View view2 = LayoutInflater.from(this).inflate(R.layout.item_record, null);
                                TextView mTvJilu2 = (TextView) view2.findViewById(R.id.tv_jilu);
                                TextView mTvJilushijian2 = (TextView) view2.findViewById(R.id.tv_jilushijian);
                                MyGridView gridView2 = (MyGridView) view2.findViewById(R.id.gridview2);
                                recordModel record = new recordModel();
                                record = orderDetil.getAssignmentList().get(j).getRecordList().get(i);
                                mTvJilu2.setText("记录" + (i + 1) + ":" + record.getContent());
                                mTvJilushijian2.setText("进行时间:" + record.getRecordTime());
                                if (record.getPictureUrl() != null) {
                                    mList.addAll(record.getPictureUrl());
                                    mAdapter2 = new ImageAdapter(this, mList);
                                    gridView2.setAdapter(mAdapter2);
                                }
                                weixiujilu2.addView(view2);
                            }
                        }
                    }
                }
//            View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
//            TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
//            TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
//            TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
//            buMeng.setText("部门：" + orderDetil.getMaintainList().get(0).getDepartmentName());
//            renYuan.setText("人员：" + orderDetil.getMaintainList().get(0).getName());
//            if (orderDetil.getMaintainList().get(0).getBeginTime() != null) {
//                mTvJilushijian.setText("进行时间：" + orderDetil.getMaintainList().get(0).getBeginTime());
//            }
//            weixiujilu.addView(view);
            }


            for (int i = 0; i < orderDetil.getAssignmentList().size(); i++) {
                View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
                TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
                TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
                TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
                TextView mTvWanchengshijian = (TextView) view.findViewById(R.id.tv_wanchengshijian);
                TextView transferReason = (TextView) view.findViewById(R.id.transferReason);
                TextView reprocessReason = (TextView) view.findViewById(R.id.reprocessReason);
                TextView jilu = (TextView) view.findViewById(R.id.jilu);
                TextView title = (TextView) view.findViewById(R.id.title);
                LinearLayout linTitle = (LinearLayout) view.findViewById(R.id.lin_title);
                if (i == 0) {
                    linTitle.setVisibility(View.VISIBLE);
                } else {
                    linTitle.setVisibility(View.GONE);
                }
                jilu.setText("记录" + (i + 1));
                title.setText("分配信息");
                buMeng.setText("部门：" + orderDetil.getAssignmentList().get(i).getDepartmentName());
                renYuan.setText("人员：" + orderDetil.getAssignmentList().get(i).getName());
                mTvJilushijian.setText("分配时间：" + orderDetil.getAssignmentList().get(i).getAssignedTime());
//                mTvWanchengshijian.setText("完成时间：" + orderDetil.getAssignmentList().get(i).getCompleteTime());
                if (orderDetil.getAssignmentList().get(i).getTransferReason() != null) {
                    transferReason.setVisibility(View.VISIBLE);
                    transferReason.setText("申请转派原因：" + orderDetil.getAssignmentList().get(i).getTransferReason());
                }
                if (orderDetil.getAssignmentList().get(i).getReprocessReason() != null) {
                    reprocessReason.setVisibility(View.VISIBLE);
                    reprocessReason.setText("再次处理原因：" + orderDetil.getAssignmentList().get(i).getReprocessReason());
                }
                mTvWanchengshijian.setVisibility(View.GONE);
                fengpeixx.addView(view);
            }
        } else {
            if (orderDetil.getAssignmentList() != null) {
                for (int j = 0; j < orderDetil.getAssignmentList().size(); j++) {
                    if (orderDetil.getAssignmentList().get(j).getRecordList().size() > 0) {//
                        View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
                        TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
                        TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
                        TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
                        TextView title = (TextView) view.findViewById(R.id.title);
                        TextView jilu = (TextView) view.findViewById(R.id.jilu);
                        TextView tv_wanchengshijian = (TextView) view.findViewById(R.id.tv_wanchengshijian);
                        TextView line = (TextView) view.findViewById(R.id.line);
                        LinearLayout linTitle = (LinearLayout) view.findViewById(R.id.lin_title);
                        LinearLayout weixiujilu2 = (LinearLayout) view.findViewById(R.id.weixiujilu);
//                        if (j == 0) {
//                            linTitle.setVisibility(View.VISIBLE);
//                        } else {
//                            linTitle.setVisibility(View.GONE);
//                        }
                        linTitle.setVisibility(View.GONE);

                        title.setText("维修记录");
                        buMeng.setText("部门：" + orderDetil.getAssignmentList().get(j).getDepartmentName());
                        renYuan.setText("人员：" + orderDetil.getAssignmentList().get(j).getName());
                        mTvJilushijian.setText("分配时间：" + orderDetil.getAssignmentList().get(j).getAssignedTime());
                        buMeng.setVisibility(View.GONE);//处理人员不显示
                        renYuan.setVisibility(View.GONE);
                        jilu.setVisibility(View.GONE);
                        mTvJilushijian.setVisibility(View.GONE);
                        tv_wanchengshijian.setVisibility(View.GONE);
                        line.setVisibility(View.GONE);
                        weixiujilu.addView(view);
                        weixiujilu.getChildAt(0).findViewById(R.id.lin_title).setVisibility(View.VISIBLE);
//                        int count=weixiujilu.getChildCount();
//                        for (int i=0;i<count-1;i++){
//                            weixiujilu.removeViewAt(0);
//                        }
                        if (orderDetil.getAssignmentList().get(j).getRecordList().size() > 0) {
                            for (int i = 0; i < orderDetil.getAssignmentList().get(j).getRecordList().size(); i++) {
                                List<String> mList = new ArrayList<>();
                                View view2 = LayoutInflater.from(this).inflate(R.layout.item_record, null);
                                TextView mTvJilu2 = (TextView) view2.findViewById(R.id.tv_jilu);
                                TextView mTvJilushijian2 = (TextView) view2.findViewById(R.id.tv_jilushijian);
                                MyGridView gridView2 = (MyGridView) view2.findViewById(R.id.gridview2);
                                recordModel record = new recordModel();
                                record = orderDetil.getAssignmentList().get(j).getRecordList().get(i);
                                mTvJilu2.setText("记录" + (i + 1) + ":" + record.getContent());
                                mTvJilushijian2.setText("时间:" + record.getRecordTime());
                                if (record.getPictureUrl() != null) {
                                    mList.addAll(record.getPictureUrl());
                                    mAdapter2 = new ImageAdapter(this, mList);
                                    gridView2.setAdapter(mAdapter2);
                                }
                                weixiujilu2.addView(view2);
                            }
                        }
                    }
                }
//            View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
//            TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
//            TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
//            TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
//            buMeng.setText("部门：" + orderDetil.getMaintainList().get(0).getDepartmentName());
//            renYuan.setText("人员：" + orderDetil.getMaintainList().get(0).getName());
//            if (orderDetil.getMaintainList().get(0).getBeginTime() != null) {
//                mTvJilushijian.setText("进行时间：" + orderDetil.getMaintainList().get(0).getBeginTime());
//            }
//            weixiujilu.addView(view);
            }
        }
        if (state == 4) {
            linShouliPublic.setVisibility(View.GONE);
        }
        if (close.getText().toString().equals("转报修")) {//如果按钮是转报修，就有按钮
            close.setVisibility(View.VISIBLE);
        }
        if (orderDetil.isTurnRepair()) {
            mBtnAgain.setVisibility(View.GONE);//如果是转报修，那就隐藏再次处理
        }
    }

    /**
     * 给个人信息放置数据的方法
     *
     * @param orderDetil
     */
    public void setData2(OrderDetil orderDetil) {
        mTvAddress.setText(orderDetil.getAddress());
        mTvtName.setText(orderDetil.getApplicationName());
        mTvNumber.setText(orderDetil.getPhoneNumber());
        if (!TextUtils.isEmpty(orderDetil.getType())) {
            mTvLeixing.setText("报修类型:" + orderDetil.getType());
            mTvLeixing.setVisibility(View.VISIBLE);
        } else {
            mTvLeixing.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(orderDetil.getProject())) {
            mTvLeixing.setText("报修项目:" + orderDetil.getProject());
            mTvLeixing.setVisibility(View.VISIBLE);
        } else {
            mTvLeixing.setVisibility(View.GONE);
        }
        if (tag == 1 || tag == 2) {
            mTvNeirong.setText("报修内容:" + orderDetil.getContent());
            mTvShijian.setText("报修时间:" + orderDetil.getCreateTime());
        } else if (tag == 3) {
            mTvNeirong.setText("投诉内容:" + orderDetil.getContent());
            mTvShijian.setText("投诉时间:" + orderDetil.getCreateTime());
        } else if (tag == 4) {
            mTvNeirong.setText("建议内容:" + orderDetil.getContent());
            mTvShijian.setText("建议时间:" + orderDetil.getCreateTime());
        }
        mTvLaiyuan.setText("工单来源:" + orderDetil.getSource());
        if (!TextUtils.isEmpty(orderDetil.getLevel())) {
            mTvJibie.setText("报修级别:" + orderDetil.getLevel());
        } else {
            lin_jibie.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(orderDetil.getCommentContent())) {
            linFuwu.setVisibility(View.VISIBLE);
            mTvPingjianierong.setText(orderDetil.getCommentContent());
            mTvPingjiashijian.setText(orderDetil.getCommentTime());
            mRating.setRating(orderDetil.getStar());
        }
        if (orderDetil.getComment() != null) {
            linFuwu.setVisibility(View.VISIBLE);
            mTvPingjianierong.setText(orderDetil.getComment().getCommentContent());
            mTvPingjiashijian.setText(orderDetil.getComment().getCommentTime());
            mRating.setRating(orderDetil.getComment().getStar());
        }
        if (orderDetil.getVisit() != null) {
            linHuifang.setVisibility(View.VISIBLE);
            mHuifangPj.setText(orderDetil.getVisit().getVisitContent());
            MtvHuifangname.setText(orderDetil.getVisit().getVisitName() + "   " + orderDetil.getVisit().getVisitPhone());
            mTvHuifangshijian.setText(orderDetil.getVisit().getVisitTime());
            liRevisit.setVisibility(View.GONE);
        }
        if (orderDetil.getPictureUrl() != null) {
            mList.addAll(orderDetil.getPictureUrl());
            mAdapter = new ImageAdapter(this, mList);
            mGridView.setAdapter(mAdapter);
        }
        if (!TextUtils.isEmpty(orderDetil.getCloseReason())) {
            if (MyApp.instance.isManage() && state == 2) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.VISIBLE);
                linShouliPublic.setVisibility(View.GONE);

            } else if (state == 2) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.VISIBLE);
                mBtnClose.setBackgroundResource(R.color.gray);
                mBtnClose.setText("已申请关闭");
                linShouliPublic.setVisibility(View.GONE);
            } else if (state == 4) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.GONE);
                linShouliPublic.setVisibility(View.GONE);
                liClose.setVisibility(View.VISIBLE);
                mBtnClose.setBackgroundResource(R.color.gray);
                mBtnClose.setText("已关闭工单");
                liRevisit.setVisibility(View.GONE);
            }
        }
        if (orderDetil.getRepairBill() != null) {
            if (!MyApp.instance.isManage()) {
                linShouliPublic.setVisibility(View.GONE);
                mBtnClose.setText("待支付：" + orderDetil.getRepairBill().getMoney() + "元");
                mBtnClose.setBackgroundResource(R.color.gray);
                liClose.setVisibility(View.VISIBLE);
            } else {
                mBtnClose.setText("待支付：" + orderDetil.getRepairBill().getMoney() + "元");
                mBtnClose.setBackgroundResource(R.color.gray);
                liClose.setVisibility(View.VISIBLE);
            }
            if (orderDetil.getRepairBill().getBillingStatus().equals("已支付")) {
                liClose.setVisibility(View.GONE);//如果是已经支付，就去掉
            }
        }
        if (!MyApp.instance.isManage() && tag == 2 && state == 4) {
            linShouliPublic.setVisibility(View.GONE);
        }
        if (orderDetil.getRepairBill() != null) {
            if (orderDetil.getRepairBill().getBillingStatus().equals("已支付")) {
                Lin_money.setVisibility(View.VISIBLE);
                money.setText(orderDetil.getRepairBill().getMoney() + "元");
            }
        }
        mTvFushijiang.setText("服务时间:" + orderDetil.getServiceTime());
        if (orderDetil.getMaintainList() != null) {
            //这个地方已经被处理人员申请转派，但管理员不知道，点进来后报错，
//            if (orderDetil.getMaintainList().size()==0)
//                return;
            if (orderDetil.getMaintainList().get(0).getRecordList().size() > 0) {
                close.setVisibility(View.GONE);//有记录就去掉申请关闭按钮
                for (int i = 0; i < orderDetil.getMaintainList().get(0).getRecordList().size(); i++) {
                    List<String> mList = new ArrayList<>();
                    View view = LayoutInflater.from(this).inflate(R.layout.item_record, null);
                    TextView mTvJinxingshijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
                    TextView mTvJilu = (TextView) view.findViewById(R.id.tv_jilu);
                    TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jilushijian);
                    MyGridView gridView2 = (MyGridView) view.findViewById(R.id.gridview2);
                    mTvJilu.setText("记录" + (i + 1) + ":" + orderDetil.getMaintainList().get(0).getRecordList().get(i).getContent());
                    mTvJilushijian.setText("时间:" + orderDetil.getMaintainList().get(0).getRecordList().get(i).getRecordTime());
                    if (orderDetil.getMaintainList().get(0).getRecordList().get(i).getPictureUrl() != null) {
                        mList.addAll(orderDetil.getMaintainList().get(0).getRecordList().get(i).getPictureUrl());
                    }
                    mAdapter2 = new ImageAdapter(this, mList);
                    gridView2.setAdapter(mAdapter2);
                    liucheng.addView(view);
                }
            }
            View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
            TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
            TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
            TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
            TextView mTvWanchengshijian = (TextView) view.findViewById(R.id.tv_wanchengshijian);
            TextView jilu = (TextView) view.findViewById(R.id.jilu);
            TextView tv_wanchengshijian = (TextView) view.findViewById(R.id.tv_wanchengshijian);
            TextView line = (TextView) view.findViewById(R.id.line);
            buMeng.setText("部门：" + orderDetil.getMaintainList().get(0).getDepartmentName());
            renYuan.setText("人员：" + orderDetil.getMaintainList().get(0).getName());
            if (orderDetil.getMaintainList().get(0).getBeginTime() != null) {
                mTvJilushijian.setText("进行时间：" + orderDetil.getMaintainList().get(0).getBeginTime());
            }
            if (!TextUtils.isEmpty(orderDetil.getMaintainList().get(0).getCompleteTime())) {
                mTvWanchengshijian.setText("完成时间：" + orderDetil.getMaintainList().get(0).getCompleteTime());
            } else {
                mTvWanchengshijian.setVisibility(View.GONE);
            }
            if (!MyApp.instance.isManage()) {//如果是处理人员，去掉分配信息
                buMeng.setVisibility(View.GONE);//处理人员不显示
                renYuan.setVisibility(View.GONE);
                jilu.setVisibility(View.GONE);
                mTvJilushijian.setVisibility(View.GONE);
                tv_wanchengshijian.setVisibility(View.GONE);
                line.setVisibility(View.GONE);
            }
            //没有维修记录就不要
            if (orderDetil.getMaintainList().get(0).getRecordList().size() != 0) {
                weixiujilu.addView(view);
            }

        }
        if (MyApp.instance.isManage() && orderDetil.getAssignmentList() != null) {
            for (int i = 0; i < orderDetil.getAssignmentList().size(); i++) {
                View view = LayoutInflater.from(this).inflate(R.layout.item_weixiujilu, null);
                TextView buMeng = (TextView) view.findViewById(R.id.tv_bumen2);
                TextView renYuan = (TextView) view.findViewById(R.id.tv_renyuan2);
                TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jinxingshijian);
                TextView mTvWanchengshijian = (TextView) view.findViewById(R.id.tv_wanchengshijian);
                TextView transferReason = (TextView) view.findViewById(R.id.transferReason);
                TextView reprocessReason = (TextView) view.findViewById(R.id.reprocessReason);
                TextView title = (TextView) view.findViewById(R.id.title);
                LinearLayout linTitle = (LinearLayout) view.findViewById(R.id.lin_title);
                TextView jilu = (TextView) view.findViewById(R.id.jilu);
                if (i == 0) {
                    linTitle.setVisibility(View.VISIBLE);
                } else {
                    linTitle.setVisibility(View.GONE);
                }
                jilu.setText("记录" + (i + 1));
                title.setText("分配信息");
                buMeng.setText("部门：" + orderDetil.getAssignmentList().get(i).getDepartmentName());
                renYuan.setText("人员：" + orderDetil.getAssignmentList().get(i).getName());
                mTvJilushijian.setText("分配时间：" + orderDetil.getAssignmentList().get(i).getAssignedTime());
//                mTvWanchengshijian.setText("完成时间：" + orderDetil.getAssignmentList().get(i).getCompleteTime());
                mTvWanchengshijian.setVisibility(View.GONE);
                if (!TextUtils.isEmpty(orderDetil.getAssignmentList().get(i).getTransferReason())) {
                    transferReason.setVisibility(View.VISIBLE);
                    transferReason.setText("申请转派原因：" + orderDetil.getAssignmentList().get(i).getTransferReason());
                }
                if (orderDetil.getAssignmentList().get(i).getReprocessReason() != null) {
                    reprocessReason.setVisibility(View.VISIBLE);
                    reprocessReason.setText("再次处理原因：" + orderDetil.getAssignmentList().get(i).getReprocessReason());
                }
                fengpeixx.addView(view);
            }
        }
    }

    /**
     * 给建议信息放置数据的方法
     *
     * @param orderDetil
     */
    public void setData4(OrderDetil orderDetil) {
        mTvAddress.setText(orderDetil.getAddress());
        mTvtName.setText(orderDetil.getApplicationName());
        mTvNumber.setText(orderDetil.getPhoneNumber());
        if (!TextUtils.isEmpty(orderDetil.getType())) {
            mTvLeixing.setText("报修类型:" + orderDetil.getType());
        } else {
            mTvLeixing.setVisibility(View.GONE);
        }
        if (tag == 1 || tag == 2) {
            mTvNeirong.setText("报修内容:" + orderDetil.getContent());
            mTvShijian.setText("报修时间:" + orderDetil.getCreateTime());
        } else if (tag == 3) {
            mTvNeirong.setText("投诉内容:" + orderDetil.getContent());
            mTvShijian.setText("投诉时间:" + orderDetil.getCreateTime());
        } else if (tag == 4) {
            mTvNeirong.setText("建议内容:" + orderDetil.getContent());
            mTvShijian.setText("建议时间:" + orderDetil.getCreateTime());
        }
        mTvLaiyuan.setText("工单来源:" + orderDetil.getSource());
        if (!TextUtils.isEmpty(orderDetil.getLevel())) {
            mTvJibie.setText("报修级别:" + orderDetil.getLevel());
        } else {
            lin_jibie.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(orderDetil.getCommentContent())) {
            linFuwu.setVisibility(View.VISIBLE);
            mTvPingjianierong.setText(orderDetil.getCommentContent());
            mTvPingjiashijian.setText(orderDetil.getCommentTime());
            mRating.setRating(orderDetil.getStar());
        }
        if (orderDetil.getComment() != null) {
            linFuwu.setVisibility(View.VISIBLE);
            mTvPingjianierong.setText(orderDetil.getComment().getCommentContent());
            mTvPingjiashijian.setText(orderDetil.getComment().getCommentTime());
            mRating.setRating(orderDetil.getComment().getStar());
        }
        if (!TextUtils.isEmpty(orderDetil.getVisitContent())) {
            linHuifang.setVisibility(View.VISIBLE);
            mHuifangPj.setText(orderDetil.getVisitContent());
            MtvHuifangname.setText(orderDetil.getVisitName() + "   " + orderDetil.getVisitPhone());
            mTvHuifangshijian.setText(orderDetil.getVisitName());
        }
        if (orderDetil.getPictureUrl() != null) {
            mList.addAll(orderDetil.getPictureUrl());
            mAdapter = new ImageAdapter(this, mList);
            mGridView.setAdapter(mAdapter);
        }
        if (!TextUtils.isEmpty(orderDetil.getServiceTime())) {
            mTvFushijiang.setText(orderDetil.getServiceTime());
        } else {
            mTvFushijiang.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(orderDetil.getCloseReason())) {
            if (MyApp.instance.isManage() && state == 2) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.VISIBLE);
                linShouliPublic.setVisibility(View.GONE);
            } else if (state == 2) {
                linClosereson.setVisibility(View.VISIBLE);
                mTvClosereason.setText(orderDetil.getCloseReason());
                liClose.setVisibility(View.VISIBLE);
                mBtnClose.setBackgroundResource(R.color.gray);
                mBtnClose.setText("已申请关闭");
                linShouliPublic.setVisibility(View.GONE);
            }
        }
        if (orderDetil.getRepairBill() != null) {
            if (!MyApp.instance.isManage()) {
                linShouliPublic.setVisibility(View.GONE);
            } else {
                mBtnClose.setText("待支付：" + orderDetil.getRepairBill().getMoney() + "元");
                mBtnClose.setBackgroundResource(R.color.gray);
                liClose.setVisibility(View.VISIBLE);
            }
        }
        if (!MyApp.instance.isManage() && tag == 2 && state == 4) {
            linShouliPublic.setVisibility(View.GONE);
        }
        if (orderDetil.getMaintainList() != null) {
            if (orderDetil.getMaintainList().get(0).getRecordList().size() > 0) {
                View view = LayoutInflater.from(this).inflate(R.layout.item_record, null);
                TextView mTvJilu = (TextView) view.findViewById(R.id.tv_jilu);
                TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jilushijian);
                MyGridView gridView2 = (MyGridView) view.findViewById(R.id.gridview2);
                mTvJilu.setText("记录：" + orderDetil.getRecord());
                mTvJilushijian.setText("时间" + orderDetil.getRecordTime());
                mList2.addAll(orderDetil.getAdvisedPhotoList());
                mAdapter2 = new ImageAdapter(this, mList2);
                gridView2.setAdapter(mAdapter2);
                liucheng.addView(view);
            }
        }
        if (tag == 4) {
            View view = LayoutInflater.from(this).inflate(R.layout.item_record, null);
            TextView mTvJilu = (TextView) view.findViewById(R.id.tv_jilu);
            TextView mTvJilushijian = (TextView) view.findViewById(R.id.tv_jilushijian);
            MyGridView gridView2 = (MyGridView) view.findViewById(R.id.gridview2);
            mTvJilu.setText("记录：" + orderDetil.getRecord());
            mTvJilushijian.setText("时间" + orderDetil.getRecordTime());
            mList2.addAll(orderDetil.getAdvisedPhotoList());
            mAdapter2 = new ImageAdapter(this, mList2);
            gridView2.setAdapter(mAdapter2);
            chulijilu.setVisibility(View.VISIBLE);
            chulijilu.addView(view);
        }
    }

    @Override
    public void onLoad() {
        handler.postDelayed(runnable, 0);
    }

    @Override
    public void onRefresh() {
        handler.postDelayed(runnable, 1500);
        weixiujilu.removeAllViews();
        fengpeixx.removeAllViews();
        chulijilu.removeAllViews();
        liucheng.removeAllViews();
        mList.clear();
        mList2.clear();
        getOrderDetil();
    }

//    @Override
//    public void onResume() {
//        super.onResume();
//        getOrderDetil();
//    }

}
